package com.example.zhou.application;

import android.app.Activity;
import android.app.Application;


import com.example.zhou.receiver.ConnectivityReceiver;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import okhttp3.Cache;

/**
 * Created by 11065 on 2016/7/21.
 */
public class MyApplication extends Application {

    private static MyApplication mInstance;
    private static Map<String, Activity> destoryMap = new HashMap<>();
    public static Cache cache;


    @Override
    public void onCreate() {
        mInstance = this;
        super.onCreate();
        File file = this.getFilesDir();
        if (file != null) {
            final File cacheDir = new File(file, "Zhihunws");
            cache = new Cache(cacheDir, 1024 * 1024 * 10);
        }
        // x.Ext.setDebug(BuildConfig.DEBUG);

    }


    public static void addDestoryActivity(Activity activity, String activityName) {
        destoryMap.put(activityName, activity);
    }

    /**
     * 销毁指定Activity
     */
    public static void destoryActivity(String activityName) {
        Set<String> keySet = destoryMap.keySet();
        for (String key : keySet) {
            destoryMap.get(key).finish();
        }
    }

    public static synchronized MyApplication getInstance() {
        return mInstance;
    }

    public void setConnectivityListener(ConnectivityReceiver.ConnectivityReceiverListener listener) {
        ConnectivityReceiver.connectivityReceiverListener = listener;
    }
}
